Kinetis SDK API Reference Manual  1.0.0-beta
Freescale Semiconductor, Inc.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
fsl_gpio_driver.h File Reference

The GPIO driver uses the virtual GPIO name rather than an actual port and a pin number. More...

#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include "fsl_port_hal.h"
#include "fsl_gpio_hal.h"

Data Structures

struct  gpio_input_pin_t
 The GPIO input pin configuration structure. More...
 
struct  gpio_output_pin_t
 The GPIO output pin configuration structure. More...
 
struct  gpio_input_pin_user_config_t
 The GPIO input pin structure. More...
 
struct  gpio_output_pin_user_config_t
 The GPIO output pin structure. More...
 

Macros

GPIO Pin Macros
#define GPIO_PINS_OUT_OF_RANGE   (0xFFFFFFFFU)
 Indicates the end of a pin configuration structure. More...
 
#define GPIO_PORT_SHIFT   (0x8U)
 Bits shifted for the GPIO port number. More...
 
#define GPIO_MAKE_PIN(r, p)   (((r)<< GPIO_PORT_SHIFT) | (p))
 Combines the port number and the pin number into a single scalar value. More...
 
#define GPIO_EXTRACT_PORT(v)   (((v) >> GPIO_PORT_SHIFT) & 0xFFU)
 Extracts the port number from a combined port and pin value. More...
 
#define GPIO_EXTRACT_PIN(v)   ((v) & 0xFFU)
 Extracts the pin number from a combined port and pin value. More...
 

Typedefs

typedef void(* gpio_isr_callback_t )(void)
 The GPIO ISR callback function.
 

Functions

Initialization
void gpio_init (const gpio_input_pin_user_config_t *inputPins, const gpio_output_pin_user_config_t *outputPins)
 Initialize all GPIO pins used by board. More...
 
void gpio_input_pin_init (const gpio_input_pin_user_config_t *inputPin)
 Initializes one GPIO input pin used by board. More...
 
void gpio_output_pin_init (const gpio_output_pin_user_config_t *outputPin)
 Initializes one GPIO output pin used by board. More...
 
Pin Direction
uint32_t gpio_get_pin_direction (uint32_t pinName)
 Gets the current direction of the individual GPIO pin. More...
 
void gpio_set_pin_direction (uint32_t pinName, gpio_pin_direction_t direction)
 Sets the current direction of the individual GPIO pin. More...
 
Output Operations
void gpio_write_pin_output (uint32_t pinName, uint32_t output)
 Sets the output level of the individual GPIO pin to the logic 1 or 0. More...
 
void gpio_set_pin_output (uint32_t pinName)
 Sets the output level of the individual GPIO pin to the logic 1. More...
 
void gpio_clear_pin_output (uint32_t pinName)
 Sets the output level of the individual GPIO pin to the logic 0. More...
 
void gpio_toggle_pin_output (uint32_t pinName)
 Reverses current output logic of the individual GPIO pin. More...
 
Input Operations
uint32_t gpio_read_pin_input (uint32_t pinName)
 Reads the current input value of the individual GPIO pin. More...
 
Interrupt
void gpio_clear_pin_interrupt_flag (uint32_t pinName)
 Clears the individual GPIO pin interrupt status flag. More...
 
void gpio_register_isr_callback_function (uint32_t pinName, gpio_isr_callback_t function)
 Registers the GPIO ISR callback function. More...
 

Detailed Description

By using the virtual name, each pin name is self-explanatory. To use the GPIO driver, an enumeration variable must be predefined in the user application files. The variable saves all GPIO pin information used in a project.

This is an example to define the enumeration variable.

// This is the enum to define virtual GPIO pin names.
// These members will be used by "uint32_t pinName" in gpio_output_pin_user_config_t
// and gpio_input_pin_user_config_t. Usually defined in a header file.
enum _gpio_pins
{
kGpioLED1 = GPIO_MAKE_PIN(HW_GPIOA, 5), // Orange LED.
kGpioLED2 = GPIO_MAKE_PIN(HW_GPIOA, 6), // Yellow LED.
kGpioLED3 = GPIO_MAKE_PIN(HW_GPIOA, 7), // Breen LED.
kGpioLED4 = GPIO_MAKE_PIN(HW_GPIOB, 8), // Red LED.
};